package com.tuo51.childcare.repository;

import com.tuo51.childcare.domain.feed.Feeds;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FeedsRepository extends JpaRepository<Feeds,String> {
    @Modifying
    @Query(value = "update user_feeds f set deleted = true where f.uid = ?1 and f.type = ?2  ", nativeQuery = true)
    void deleteAllByFeedsUserIdAndFeedType(String uid, Integer feedType);

    @Modifying
    @Query(value = "update user_feeds f set deleted = true where f.uid = ?1  ", nativeQuery = true)
    void deleteAllByUserFeeds(String uid);

    @Modifying
    @Query(value = "update user_feeds f set deleted = true where f.linkId = ?1  ", nativeQuery = true)
    void deleteAllByRecordId(String recordId);

    Page<Feeds> findAllByUidAndDeletedIsFalseOrderByCreatedDesc(String uid, Pageable pageable);
    Page<Feeds> findAllByUidAndDeletedIsFalseAndTypeInOrderByCreatedDesc(String uid, List<Integer> type, Pageable pageable);

    Feeds getByIdAndUidAndDeletedIsFalse(String id, String uid);

    Feeds getTop1ByUidAndTypeAndDeletedIsFalseOrderByCreatedDesc(String uid, int type);

}
